package com.canplay.screen.network

import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody

/**
 * @Description: http code 405 拦截器
 */
class Code405Interceptor:Interceptor{
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        try {
            val response = chain.proceed(request)
            return  if(response.code == 405){
                response.newBuilder()
                    .code(200)
                    .body("{\"stateCode\":405,\"msg\":\"你的操作过于频繁，请稍后再试\",\"data\":null,\"success\":true}".toResponseBody(contentType = "application/json;charset=UTF-8".toMediaType()))
                    .build()
            }else{
                response
            }
        }catch (e:Exception){
            throw e
        }
    }

}